package com.olc.railing.utils;

import android.content.Context;
import android.os.Environment;

import com.olc.railing.base.BaseApplication;
import com.olc.railing.constant.Constants;

import java.io.File;

public class LogcatHelper {
    private static LogcatHelper INSTANCE = null;
    private LogDumper mLogDumper = null;
    private int mPId;
    /**
     * 初始化目录
     */
    private void init(Context context) {

        File file = new File(Constants.FILE_PATH_INFO.get(Constants.FILE_PATH_DIR_LOG));
        if (!file.exists()) {
            file.mkdirs();
            MyLog.e(MyLog.TAG,"创建文件夹");
        }
        MyLog.e(MyLog.TAG,"PATH_LOGCAT=="+Constants.FILE_PATH_INFO.get(Constants.FILE_PATH_DIR_LOG));
    }

    public static LogcatHelper getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = new LogcatHelper(context);
        }
        return INSTANCE;
    }

    private LogcatHelper(Context context) {
        init(context);
        mPId = android.os.Process.myPid();
    }

    public void start() {
        if (mLogDumper == null)
            mLogDumper = new LogDumper(String.valueOf(mPId), Constants.FILE_PATH_INFO.get(Constants.FILE_PATH_DIR_LOG));
            mLogDumper.start();
    }

    public void stop() {
        if (mLogDumper != null) {
            mLogDumper.stopLogs();
            mLogDumper = null;
        }
    }
}
